﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace System.Web.Mvc.JQueryValidation
{
	public class UrlAttribute : ValidatorAttribute
	{
		public override string JQueryRule
		{
			get
			{
				return "url: true";
			}
		}

		public override string JQueryRuleErrorMessage
		{
			get
			{
				return "url: \"" + JQueryErrorMessage + "\"";
			}
		}

		public override bool Validate(string value)
		{
			return String.IsNullOrEmpty(value) || (!String.IsNullOrEmpty(value) && Uri.IsWellFormedUriString(value, UriKind.Absolute));
		}

		public UrlAttribute(string fieldName)
			: base(String.Empty, fieldName)
		{
		}

		public UrlAttribute(string formID, string fieldName)
			: base(formID, fieldName)
		{
		}
	}
}